package com.xvxingan.mvc.mq.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import com.xvxingan.base.controller.BaseController;
import com.xvxingan.mvc.mq.service.MqService;
import com.xvxingan.mvc.mq.service.MqService3;

@Controller
@RequestMapping("/mq")
public class MQController extends BaseController {
	

	@Autowired
	private MqService3 MqService;
	@Autowired
	private MyListener myListener;
	@RequestMapping("/msg")
	public ModelAndView msg(HttpServletRequest request) {
		String name = request.getParameter("name");
		String age = request.getParameter("age");
		int count = Integer.valueOf(request.getParameter("count"));
 		Map<String,Object> headers = new HashMap<String,Object>();
		headers.put("name",name);
		headers.put("age",age);

		for(int i=0;i<count;i++){
			System.out.println("第"+i+"次");
			//向主题发送消息
			this.MqService.demo.sendBodyAndHeaders(null, headers);
		}
		return new ModelAndView(new MappingJackson2JsonView(), this.getSuccessResult());
	}

}
